package com.keson.door2;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.fastjson.JSONObject;
import com.keson.door2.util.Constant;

public class SettingActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        ((TextView)findViewById(R.id.typeId)).setText(Constant.typeId);
        ((TextView)findViewById(R.id.clientNo)).setText(Constant.clientNo);
        ((TextView)findViewById(R.id.broker)).setText(Constant.broker);
        ((TextView)findViewById(R.id.orgId)).setText(Constant.orgId);
        ((TextView)findViewById(R.id.url)).setText(Constant.url);
        ((TextView)findViewById(R.id.enter)).setText(Constant.enter+"");

        ((Button)findViewById(R.id.save)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                JSONObject config = new JSONObject();
                config.put("url", ((TextView)findViewById(R.id.url)).getText());
                config.put("enter", ((TextView)findViewById(R.id.enter)).getText());
                config.put("broker", ((TextView)findViewById(R.id.broker)).getText());
                System.out.println("???????????????????????"+config.toJSONString());
                JSONObject info = new JSONObject();
                info.put("clientNo", ((TextView)findViewById(R.id.clientNo)).getText());
                info.put("typeId", ((TextView)findViewById(R.id.typeId)).getText());
                info.put("orgId", ((TextView)findViewById(R.id.orgId)).getText());
                Constant.updateConfigToFile(config, info);

                SettingActivity.this.finish();
                Intent intent = new Intent(SettingActivity.this, MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                SettingActivity.this.startActivity(intent);
                android.os.Process.killProcess(android.os.Process.myPid());
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
}
